import Vue from 'vue'
import VueRouter from 'vue-router'

import store from '@/store'
import $api from '../http/api.js'
import Home from '../views/home/Home.vue'
import Chart from '../views/home/Chart.vue'
import Login from '../views/Login.vue'
//管理员
import AdminsList from '../components/admin/AdminsList.vue'
import AddAdmin from '../components/admin/AddAdmin.vue'
//轮播
import SwipersList from '../components/swipers/SwipersList.vue'
import AddSwipers from '../components/swipers/AddSwipers.vue'
import UpdateSwipers from '../components/swipers/UpdateSwipers.vue'
import Swipers from '../components/swipers/Swipers.vue'

//菜品
import MenusList from '../components/menus/MenusList.vue'
import MenusShow from '../components/menus/MenusShow.vue'
import UpdateMenus from '../components/menus/UpdateMenus.vue'
//会员
import MembersList from '../components/members/MembersList.vue'
// const MembersList = () => import(/* webpackChunkName: "group-members" */'../components/members/MembersList.vue');
const MealList = () => import(/* webpackChunkName: "group-meal" */'../components/meals/MealList.vue');
const UpdateMeal = () => import(/* webpackChunkName: "group-meal" */'../components/meals/UpdateMeal.vue');
const AddMeal = () => import(/* webpackChunkName: "group-meal" */'../components/meals/AddMeal.vue');

Vue.use(VueRouter)

const routes = [
	{
		path: '/',
		name: 'Home',
		component: Home,
		// 路由独享守卫
		// beforeEnter: async (to, from, next) => {
		// 	if (localStorage.token) {
		// 		const { data } = await $api.users.getUserInfo();
		// 		if (data.code) {
		// 			store.commit('SET_USER_INFO', data.data)
		// 			next()
		// 		}
		// 	} else {
		// 		alert('你还未登陆，请先登陆');
		// 		next('/login');
		// 	}
		// },
		children: [
			{
				path: '',
				component: Chart
			},
			//管理员
			{
				path: 'adminsList',
				name: 'AdminsList',
				component: AdminsList,
				meta: {
					tittle: '管理员模块',
					tittle2: '管理员列表'
				}
			},
			{
				path: 'addAdmin',
				name: 'AddAdmin',
				component: AddAdmin,
				meta: {
					tittle: '管理员模块',
					tittle2: '新增管理员'
				}
			},
			//轮播
			{
				path: 'swipersList',
				name: 'SwipersList',
				component: SwipersList,
				meta: {
					tittle: '轮播图模块',
					tittle2: '轮播图列表'
				}
			},
			{
				path: 'addSwipers',
				name: 'AddSwipers',
				component: AddSwipers,
				meta: {
					tittle: '轮播图模块',
					tittle2: '新增轮播图'
				}
			},
			{
				path: 'updateSwipers/:_id',
				name: 'UpdateSwipers',
				component: UpdateSwipers,
				meta: {
					tittle: '轮播图模块',
					tittle2: '修改轮播图'
				}
			},
			{
				path: 'swipers/:_id',
				name: 'Swipers',
				component: Swipers,
				meta: {
					tittle: '轮播图模块',
					tittle2: '轮播图其他操作'
				}
			},
			//菜品管理
			{
				path: 'menusList',
				name: 'MenusList',
				component: MenusList,
				meta: {
					tittle: '菜品管理',
					tittle2: '菜品展示'
				}
			},
			{
				path: 'menusShow/:_id',
				name: 'MenusShow',
				component: MenusShow,
				meta: {
					tittle: '菜品管理',
					tittle2: '菜品详情'
				}
			},
			{
				path: 'updateMenus/:_id',
				name: 'UpdateMenus',
				component: UpdateMenus,
				meta: {
					tittle: '菜品管理',
					tittle2: '修改菜品'
				}
			},

			//会员
			{
				path: 'membersList',
				name: 'MembersList',
				component: MembersList,
				meta: {
					title1: '会员管理',
					title2: '会员列表'
				}
			},
			//套餐
			{
				path: 'mealList',
				name: 'MealList',
				component: MealList,
				meta: {
					title1: '套餐管理',
					title2: '套餐列表'
				}
			},
			{
				path: 'updateMeal/:_id?',
				name: 'UpdateMeal',
				component: UpdateMeal,
				meta: {
					title1: '套餐管理',
					title2: '修改套餐'
				}
			},
			{
				path: 'addMeal',
				name: 'AddMeal',
				component: AddMeal,
				meta: {
					title1: '套餐管理',
					title2: '添加套餐'
				}
			},
		]
	},
	{
		path: '/login',
		name: 'Login',
		component: Login
	},
	{
		path: '*',
		name: 'Error',
		component: () => import('../views/error/Error.vue')
	}
]

const router = new VueRouter({
	routes,
	mode: 'history'
})

export default router
